package cn.itsource.basic.base.controller;

import cn.itsource.basic.base.service.ILoginService;
import cn.itsource.basic.utils.AjaxResult;
import cn.itsource.org.domain.dto.SmsCodeParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private ILoginService loginService;

    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult verifyCodeImage(@PathVariable("imageCodeKey") String key){
        try {
            return AjaxResult.me().setResultObj(loginService.image(key));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage()).setSuccess(false);
        }
    }

    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SmsCodeParam param){
        try {
            loginService.sendSmsCode(param);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage()).setSuccess(false);
        }
    }
}
